<template>
    <div class="balance">
        <c-top-back></c-top-back>
        <r-messages :src="src" msg="我的账户余额" :money="money" class="account" :fivetext="fivetext">
            <div slot="list" class="slot">
                <r-group>
                    <r-cell title="提现账号" :value="txtStatus" :is-link="islink" :link="link"
                            :class="{flag:isShow}"></r-cell>
                    <r-cell title="提现记录" link="/tx/cashrecord" is-link></r-cell>
                </r-group>
            </div>
            <div slot="btn">
                <r-button type="primary" text="提现" @click.native="btnClick" :disabled="btnDisabled"></r-button>
            </div>
        </r-messages>
        <div class="hint">
            <h3>
                <r-icon type="info"></r-icon>
                温馨提示
            </h3>
            1.提现手续费：3元/笔
            <br/>2.通道手续费：提现金额的0.6%
            <br/>3.提现计算公式：实际提现金额=提现金额-通道手续费-提现手续费
            <br/>4.例：申请提现1000元
            <br/>5.实际提现金额：1000-1000*0.6%-3=991元
        </div>
    </div>

</template>
<script>
    import utils from '../../libs/utils.js'
    export default {
        data (){
            return {
                src: "",
                money: 0,
                desc: "提现预计24小时后到账",
                btnDisabled: true,
                txtStatus: "",
                islink: true,
                link: "/tx/verifyInfo",
                accountInfo: {},
                isShow: false,
                fivetext: "提现预计24小时后到账",
                bindCard: false,//是否绑卡成功
                rzStatus: "",
            }
        },
        mounted: function () {
            this.$nextTick(function () {
                let that = this;
                //可提现金额
                utils.ajax({
                    url: "/seller/account/getAccountAmount",
                    success: function (res) {
                        if (res.code == "SUCCESS") {
                            let json = res.result;
                            that.money = utils.formatPrice(json.withdrawals_amount);
                        } else {
                            that.$vux.alert.show(res.message);
                        }
                    }
                })
                //认证信息
                utils.ajax({
                    url: "/seller/account/get",
                    success: function (res) {
                        if (res.code == "SUCCESS") {
                            if (res.result) {
                                that.txtStatus = "实名验证已通过";
                                that.islink = false;
                                that.link = "";
                                that.accountInfo = res.result;
                                utils.ajax({
                                    url: "/seller/account/getStoreBankCard",
                                    success: function (response) {
                                        if (response.code == "SUCCESS") {
                                            that.isShow = true;
                                            that.txtStatus = response.result.card_no;
                                            that.bindCard = true;//绑卡成功
                                            if (res.result.account_type == 1) {
                                                switch (response.result.card_auth_status) {
                                                    case "RZZ":
                                                        that.fivetext = "银行账户认证待审核，需要等待1个工作日！";
                                                        that.btnDisabled = true;
                                                        break;
                                                    case "RZCG":
                                                        that.fivetext = "提现预计24小时后到账";
                                                        that.btnDisabled = false;
                                                        break;
                                                    case "RZSB":
                                                        that.fivetext = "银行账户认证失败，请重新编辑提现账号！";
                                                        that.rzStatus = "rzsb";
                                                        that.bindCard = false;
                                                        that.btnDisabled = false;
                                                        break;
                                                }
                                            }else {
                                                that.btnDisabled = false;
                                            }
                                        } else {
                                            that.btnDisabled = false;
                                            //
                                        }
                                    }
                                });
                            } else {
                                that.txtStatus = "未实名验证";
                            }
                        } else {
                            that.$vux.alert.show(res.message);
                        }
                    }
                });
            })
        },
        methods: {
            btnClick(){
                if (this.bindCard) {
                    utils.go("/tx/withdrawals", this.$router);
                } else {
                    if (this.accountInfo.account_type == 0) {
                        //个人
                        utils.go("/tx/bindCard?type=1&name=" + this.accountInfo.user_name + "&num=" + this.accountInfo.certificate_number, this.$router);
                    } else {
                        //企业
                        utils.go("/tx/bindCard?type=2&rzStatus=" + this.rzStatus + "&company=" + this.accountInfo.company_name + "&buslince=" + this.accountInfo.buslince, this.$router);
                    }
                }


            }
        },
        components: {
            "cTopBack": require('../../components/x-top-back/x-top-back.vue'),
            "rGroup": require("../../components/group/group.vue"),
            "rButton": require("../../components/button/button.vue"),
            "rCell": require("../../components/cell/cell.vue"),
            "r-messages": require("../../components/x-messages/x-messages.vue"),
            "r-icon": require("../../components/icon/icon.vue"),
        }
    }

</script>
<style lang="less">
    @import "../../assets/styles/views/personal";
</style>